package cn.bdqn.controller;

import cn.bdqn.dao.AnnounceDaok;
import cn.bdqn.pojo.Announcement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 苏闻君
 * @Date: Created in 2020/7/18  16:21
 */
@Controller
public class AnnounceControllerk {
    @Autowired
    AnnounceDaok announceDaok;
    @RequestMapping("/index")
    public String SelectAnn(Model model){
        List<Announcement> list=announceDaok.selectAnn();
        model.addAttribute("alist",list);
        return "index";
    }

    @RequestMapping("/details")
    public String details(Model model, HttpServletRequest request,String type){

        Announcement list=new Announcement();
        if(request.getParameter("id")!=null){
            Integer id=Integer.parseInt(request.getParameter("id"));
           list=announceDaok.selectDet(id);
            model.addAttribute("list",list);
        }


        List<Announcement> tlist=announceDaok.selectType();
        model.addAttribute("tlist",tlist);

        if(request.getParameter("type")!=null){
            type=request.getParameter("type");
             list=announceDaok.selectGonggao(type);
            model.addAttribute("list",list);
        }
        return "blog-details";
    }

    @RequestMapping("/blog")
    public String blog(Model model){
        List<Announcement> list=announceDaok.selectAnn();
        model.addAttribute("list",list);
        List<Announcement> tlist=announceDaok.selectType();
        model.addAttribute("tlist",tlist);
        return "blog";
    }
}
